package com.dz.goods.controller;

import com.dz.common.base.BaseApiService;
import com.dz.common.base.BasePageResultsVO;
import com.dz.common.base.ResponseBase;
import com.dz.goods.domain.entity.Album;
import com.dz.goods.domain.entity.Category;
import com.dz.goods.domain.vo.AlbumParamsVO;
import com.dz.goods.domain.vo.AlbumResultsVO;
import com.dz.goods.domain.vo.CategoryParamsVO;
import com.dz.goods.domain.vo.CategoryResultsVO;
import com.dz.goods.service.AlbumService;
import com.dz.goods.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods/category")
@Api(tags = "商品分类管理")
public class CategoryController extends BaseApiService {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/get_category_list")
    @ApiOperation(value = "条件查询商品分类")
    public ResponseBase getAlbumList(CategoryParamsVO vo) throws Exception {
        BasePageResultsVO<CategoryResultsVO> categoryList = categoryService.getCategoryList(vo);
        return setResultSuccess(categoryList) ;
    }
    @PostMapping("/add")
    @ApiOperation(value = "添加商品分类")
    public ResponseBase add(@RequestBody Category category) throws Exception {
        Category add = categoryService.add(category);
        return setResultSuccess(add) ;
    }
    @PostMapping("/edit")
    @ApiOperation(value = "更新商品分类")
    public ResponseBase edit(@RequestBody Category category) throws Exception {
        Category edit = categoryService.edit(category);
        return setResultSuccess(edit) ;
    }
    @GetMapping("/get_by_id")
    @ApiOperation(value = "根据id查询商品分类")
    public ResponseBase getById(Long categoryId) throws Exception {
        Category category = categoryService.findById(categoryId);
        return setResultSuccess(category) ;
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除商品分类")
    public ResponseBase delete(Long categoryId) throws Exception {
        categoryService.delete(categoryId);
        return setResultSuccess();
    }

}